home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / INDENT3.ARJ / DOPREESC.C < prev    next >
C/C++ Source or Header  |  1992-08-04  |  2KB  |  76 lines

  1. #include "indent_globs.h"
  2.  
  3. void dopreesc()
  4. {
  5.     int in_comment = 0;
  6.     char *com_start = NULL;
  7.     char quote = '\0';
  8.     char *com_end = NULL;
  9.  
  10.     while (*buf_ptr != '\n' || in_comment) {
  11.     *e_lab = *buf_ptr++;
  12.     if (buf_ptr >= buf_end)
  13.         fill_buffer();
  14.     switch (*e_lab++) {
  15.         case BACKSLASH:
  16.         if (troff)
  17.             *e_lab++ = BACKSLASH;
  18.         if (!in_comment) {
  19.             *e_lab++ = *buf_ptr++;
  20.             if (buf_ptr >= buf_end)
  21.             fill_buffer();
  22.         }
  23.         break;
  24.         case '/':
  25.         if (*buf_ptr == '*' && !in_comment && !quote) {
  26.             in_comment = 1;
  27.             *e_lab++ = *buf_ptr++;
  28.             com_start = e_lab - 2;
  29.         }
  30.         break;
  31.         case '"':
  32.         if (quote == '"')
  33.             quote = '\0';
  34.         break;
  35.         case '\'':
  36.         if (quote == '\'')
  37.             quote = '\0';
  38.         break;
  39.         case '*':
  40.         if (*buf_ptr == '/' && in_comment) {
  41.             in_comment = 0;
  42.             *e_lab++ = *buf_ptr++;
  43.             com_end = e_lab;
  44.         }
  45.         break;
  46.     }
  47.     }
  48.     while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
  49.     e_lab--;
  50.     if (e_lab == com_end && bp_save == 0) {    /* comment on preprocessor
  51.                          * line */
  52.     if (sc_end == NULL)    /* if this is the first comment, we must set
  53.                  * up the buffer */
  54.         sc_end = &(save_com[0]);
  55.     else {
  56.         *sc_end++ = '\n';    /* add newline between comments */
  57.         *sc_end++ = ' ';
  58.         --line_no;
  59.     }
  60.     memcpy(sc_end, com_start, com_end - com_start);
  61.     sc_end += com_end - com_start;
  62.     e_lab = com_start;
  63.     while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
  64.         e_lab--;
  65.     bp_save = buf_ptr;    /* save current input buffer */
  66.     be_save = buf_end;
  67.     buf_ptr = save_com;    /* fix so that subsequent calls to lexi will
  68.                  * take tokens out of save_com */
  69.     *sc_end++ = ' ';    /* add trailing blank, just in case */
  70.     buf_end = sc_end;
  71.     sc_end = 0;
  72.     }
  73.     *e_lab = '\0';        /* null terminate line */
  74.     ps.pcase = false;
  75. }
  76.